import datetime

from flask.cli import AppGroup

from apps.extensions import db
from apps.models import Test

demo_cli = AppGroup("demo")

now_time = datetime.datetime.now()

testdata = [
    Test(
        id=1,
        username='test',
        create_at=now_time,
        enable=1,
        remark='要是不能把握时机，就要终身蹭蹬，一事无成！'
    )
]

@demo_cli.command("init")
def init_db():
    db.session.add_all(testdata)
    print("加载系统必须测试数据")
    db.session.commit()
    print("基础数据存入")
    print("数据初始化完成,请使用run脚本运行")
